﻿User.NO_MOVE = 0;
User.MOVE_UP = 1;
User.MOVE_RIGHT = 2;
User.MOVE_DOWN = 3;
User.MOVE_LEFT = 4;
User.ALIEN_START = -10;
User.HUNTER_START = 10;
User.AlienIdCounter = User.ALIEN_START;
User.HunterIdCounter = User.HUNTER_START;

function User() {
    if (arguments.length == 1) {
        var user = arguments[0];
        this.id = user.id;
        this.userName = user.userName;
        this.alien = user.alien;
        this.tokenColor = user.tokenColor;
        this.bot = user.bot;
        this.row = null;
        this.column = null;
        this.queuedMove = User.NO_MOVE;
        this.health = 100;
        this.loginTime = undefined;
        this.trackingId = null;
        this.botRandomCount = 0;
        this.botCantMoveCount = 0;
        this.botCantMovePosition = null;
        this.botCantMoveRow = null;
        this.botCantMoveColumn = null;
    }
    else {
        this.id = null;
        this.userName = null;
        this.alien = null;
        this.tokenColor = null;
        this.row = null;
        this.column = null;
        this.bot = false;
        this.queuedMove = User.NO_MOVE;
        this.health = 100;
        this.loginTime = undefined;
        this.trackingId = null;
        this.botRandomeCount = 0;
        this.botCantMoveCount = 0;
        this.botCantMoveRow = null;
        this.botCantMoveColumn = null;
    }
}

User.resetIds = function () {
    User.AlienIdCounter = User.ALIEN_START;
    User.HunterIdCounter = User.HUNTER_START;
};

User.prototype = (function () {
    return {
        constructor: User,

        setId: function () {
            this.id = this.alien ? User.AlienIdCounter-- : User.HunterIdCounter++;
            this.loginTime = new Date().getTime();
        },

        setPosition: function (row, column) {
            this.row = row;
            this.column = column;
        },

        setQueuedMove: function (move) {
            this.queuedMove = move;
        },

        clearQueuedMove: function () {
            this.queuedMove = User.NO_MOVE;
        },

        canPushBlocks: function () {
            return this.id >= User.HUNTER_START;
        },

        setHealth: function (health) {
            this.health = health;
        },

        move: function () {
            switch (this.queuedMove) {
                case User.NO_MOVE:
                    break;
                case User.MOVE_UP:
                    this.row--;
                    break;
                case User.MOVE_RIGHT:
                    this.column++;
                    break;
                case User.MOVE_DOWN:
                    this.row++;
                    break;
                case User.MOVE_LEFT:
                    this.column--;
                    break;
            }
        }
    };
})();

exports.User = User;